using System;
using System.Collections.Generic;
using TestCases.CompareAssert.Core.Compositions.Interfaces;
using TestCases.CompareAssert.Core.Interfaces;

namespace TestCases.CompareAssert.Core.Compositions
{
    public static class CompositionUtils
    {
        public static ICompositionStrategy<TItem, TResult> 
            CreateStrategy<TItem, TResult>(this CompositionType type)
            where TResult: IResultProvider
        {            
            switch (type)
            {
                case CompositionType.All:
                    return new AllStrategy<TItem, TResult>();
                    
                case CompositionType.Any:
                    return new AnyStrategy<TItem, TResult>();
                    
                case CompositionType.Single:
                    return new SingleStrategy<TItem, TResult>();
                
                default:
                    throw new ArgumentException("Invalid composition type.", "type");                  
            }
        }
        
        public static IList<ICompareResult> GetResults<T>(this IEnumerable<T> items) where T: IResultProvider
        {
            var results = new List<ICompareResult>();
            foreach (var item in items)
            {
                results.Add(item.GetResult());
            }
            return results;
        }
    }
}